require 'gadgets/combobox'
module EventEditor
  module Commands
    class ColorChange
      def self.show(base, model, edit_command = [], options = {}, &func)
       @dialog = Gtk::Dialog.new("Color Change",
               base,
               Gtk::Dialog::MODAL,
               ["OK", Gtk::Dialog::RESPONSE_OK],
               ["Cancel", Gtk::Dialog::RESPONSE_CANCEL]
               )
               
        

        @dialog.vbox.add(self.create_panel)
        @dialog.vbox.show_all

        self.load(edit_command)
        
        @dialog.run do |response|
          if response == Gtk::Dialog::RESPONSE_OK
            func.call(self.command)
          end
        end
        @dialog.destroy
      end
      
      def self.create_panel
        ## Create document
        vbox = Gtk::VBox.new
        
        hbox = Gtk::HBox.new
        hbox.add(Gtk::Label.new(' R:'))
        hbox.add(@r_input = Gtk::SpinButton.new(-255, 255, 1))
        hbox.add(Gtk::Label.new(' G:'))
        hbox.add(@g_input = Gtk::SpinButton.new(-255, 255, 1))
        hbox.add(Gtk::Label.new(' B:'))
        hbox.add(@b_input = Gtk::SpinButton.new(-255, 255, 1))
        vbox.add(hbox)
        @r_input.value = 0
        @g_input.value = 0
        @b_input.value = 0
        
        hbox = Gtk::HBox.new
        hbox.add(Gtk::Label.new(' Time:'))
        hbox.add(@time_input = Gtk::SpinButton.new(0, 9999, 1))
        hbox.add(Gtk::Label.new('Frames'))
        
        hbox.add(@wait_check = Gtk::CheckButton.new('Wait'))
        vbox.add(hbox)
        
        
        return vbox
      end

      def self.load(edit_command)
        unless edit_command.empty?
          @r_input.value = edit_command[1]
          @g_input.value = edit_command[2]
          @b_input.value = edit_command[3]
          @time_input.value = edit_command[4]
          @wait_check.active = edit_command[5]
        end
      end

      def self.command
        return ['color_change', @r_input.value.floor, @g_input.value.floor, @b_input.value.floor, @time_input.value.floor, @wait_check.active?]
      end

      def self.command_to_s(model, args, margin = "")
        t = ""
        if args[5]
          t = "(W)"
        end
        
        s = "Color Change: (#{args[1]}, #{args[2]}, #{args[3]}) #{t}#{args[4]} Frames"
        return s
      end
    end
  end
end